cmake_minimum_required(VERSION 3.14.1)
project(main) #${PROJECT_NAME}  main

#让cmake知道到include目录下找头文件
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)

#将src下面的源文件放到变量${SRC}中
aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/src SRC)

# #[[
# #让cmake知道到lib下面找库文件
# link_directories(${CMAKE_CURRENT_LIST_DIR}/lib)

# #生成静态库
# add_library(${PROJECT_NAME}_static STATIC ${CMAKE_CURRENT_LIST_DIR}/src/test.cpp)
# set_target_properties(${PROJECT_NAME}_static PROPERTIES ARCHIVE_OUTPUT_NAME "test")
# install(TARGETS ${PROJECT_NAME}_static ARCHIVE DESTINATION ${CMAKE_CURRENT_LIST_DIR}/lib)

# add_library(${PROJECT_NAME}_static2 STATIC ${CMAKE_CURRENT_LIST_DIR}/src/static_test.cpp)
# set_target_properties(${PROJECT_NAME}_static2 PROPERTIES ARCHIVE_OUTPUT_NAME "test2")
# install(TARGETS ${PROJECT_NAME}_static2 ARCHIVE DESTINATION ${CMAKE_CURRENT_LIST_DIR}/lib)

# #生成动态库

# add_library(${PROJECT_NAME}_shared SHARED ${CMAKE_CURRENT_LIST_DIR}/src/test.cpp)
# set_target_properties(${PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME "test")
# install(TARGETS ${PROJECT_NAME}_shared LIBRARY DESTINATION ${CMAKE_CURRENT_LIST_DIR}/lib)

# add_library(${PROJECT_NAME}_shared2 SHARED ${CMAKE_CURRENT_LIST_DIR}/src/shared_test.cpp)
# set_target_properties(${PROJECT_NAME}_shared2 PROPERTIES OUTPUT_NAME "test2")
# install(TARGETS ${PROJECT_NAME}_shared2 LIBRARY DESTINATION ${CMAKE_CURRENT_LIST_DIR}/lib)
# ]]

#生成可执行文件
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/src/main.cpp)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_CURRENT_LIST_DIR}/lib)

# #设置编译器编译选项
# # SET(CMAKE_C_COMPILER "gcc")
# # SET(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_FLAGS "-m32")
set(CMAKE_CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # set C++ 11
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2-DNDEBUG")
